import time
from selenium.webdriver.common.by import By
from base.mis.base import BasePage, BaseHandle
from utils import UtilsDriver, choice_channel, is_exist
class AuditPage(BasePage):
    def __init__(self):
        super().__init__()
        self.title = By.XPATH,'//*[@id="app"]/div/div[3]/div/div[2]/div/div[1]/div/input'
        self.channel = By.XPATH,'//*[@id="app"]/div/div[3]/div/div[2]/div/div[3]/div/div[1]/input'
        self.query_btn=By.XPATH,'//*[@id="app"]/div/div[3]/div/div[3]/div/div[3]/div'
        self.pass_btn=By.XPATH,'//*[@id="app"]/div/div[3]/div/div[4]/div[1]/div[3]/table/tbody/tr[1]/td[7]/div/button[2]'
        self.confirm_btn=By.CLASS_NAME,'el-button--primary'
        self.end_time=By.XPATH,'//*[@id="app"]/div/div[3]/div/div[3]/div/div[2]/div/input'
    def find_title(self):
        return self.get_element(self.title)
    def find_channel(self):
        return self.get_element(self.channel)
    def find_query_btn(self):
        return self.get_element(self.query_btn)
    def find_pass_btn(self):
        return self.get_element(self.pass_btn)
    def find_confirm_btn(self):
        return self.get_element(self.confirm_btn)
    def find_end_time(self):
        return self.get_element(self.end_time)
class AuditHandle(BaseHandle):
    def __init__(self):
        self.audit_page=AuditPage()
    def input_title(self,title):
        self.input_text(self.audit_page.find_title(),title)
    def choice_status(self,status):
        choice_channel(self.audit_page.driver,self.audit_page.find_channel(),status)
    def input_end_time(self,end_time):
        self.input_text(self.audit_page.find_end_time(),end_time)
    def click_query_btn(self):
        self.audit_page.find_query_btn().click()
    def click_pass_btn(self):
        self.audit_page.find_pass_btn().click()
    def click_confirm_btn(self):
        self.audit_page.find_confirm_btn().click()
class AuditProxy:
    def __init__(self):
        self.audit_handle=AuditHandle()
        self.driver=UtilsDriver.get_mis_driver()
    def audit_article(self,title,status,end_time):
        self.audit_handle.input_title(title)
        self.audit_handle.choice_status(status)
        self.audit_handle.input_end_time(end_time)
        self.audit_handle.click_query_btn()
        time.sleep(1)
        self.audit_handle.click_pass_btn()
        self.audit_handle.click_confirm_btn()
    def audit_article_pass(self,title):
        self.audit_handle.input_title(title)
        time.sleep(1)
        self.audit_handle.choice_status("审核通过")
        time.sleep(1)
        self.audit_handle.click_query_btn()
        time.sleep(1)
        return is_exist(self.driver,title)